#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
using namespace std;
int a[200005];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        for (int i = 1;i <= n;i++)
        {
            scanf("%d",&a[i]);
        }
        ll ans = 0;
        for (int i = 0;i < (1 << n);i++)
        {
            ll res = 0;
            int pre[2];
            pre[0] = pre[1] = 0;
            for (int j = 1;j <= n;j++)
            {
                if ((1 << (j - 1)) & i)
                {
                    res += (a[j] == a[pre[1]]) * a[j];
                    pre[1] = j;
                }
                else
                {
                    res += (a[j] == a[pre[0]]) * a[j];
                    pre[0] = j;
                }
            }
            ans = max(ans,res);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
